#ifndef UTIL
#define UTIL
#include <sys/types.h>
#include <string>

// 检查条件condition是否成立，如果不成立，则直接返回
#define CHK_RET_VLE(condition, retValue) do { \
    if (!(condition)) {                     \
        return retValue;                  \
    }                                     \
}while(0)                                 


#define CHK_RET(condition) do { \
    if (!(condition)) {                     \
        return ;                  \
    }                                     \
}while(0)                                 

#define CHK_BOOL_RET_BOOL(call) do { \
    bool succ = call;                     \
    if (!succ) {                     \
        return false;                  \
    }                                     \
}while(0)                                 

#define CHK_BOOL_RET(call) do { \
    bool succ = call;                     \
    if (!succ) {                     \
        return ;                  \
    }                                     \
}while(0)                                 

// 如果是函数调用的话，需要预先设定函数返回值
// 否则不起作用
#define CHK_RET_VLE_DEPERATED(call, retValue) do { \
    CallResutl condition = call;         \
    if (!condition) {                     \
        return retValue;                  \
    }                                     \
}while(0)                                 


ssize_t readn(int fd, void *buff, size_t n);
ssize_t writen(int fd, void *buff, size_t n);

ssize_t readn(int fd,  std::string& str);
ssize_t writen(int fd,  std::string& str);

int setNonBlocking(int fd);

#endif